using System;
using System.Collections.Generic;
using System.Text;

namespace WOWEquipOptimizer
{
    public delegate void UpdateDelegate(float value);
    public delegate void NotificationDelegate();
    /// <summary>
    /// abstract class for optimizers
    /// </summary>
    public abstract class Optimizer
    {
        protected Character m_Target;
        protected System.Random m_Random = new Random();
        public UpdateDelegate UpdateGraphics;
        protected static bool m_Abort = false;
        protected NotificationDelegate m_Notify;
        public delegate void NoticeDelegate();
        private bool m_EnableNotification = true;
        protected int m_MinLevel = 100;

        public int MinLevel
        {
            get { return m_MinLevel; }
            set { m_MinLevel = value; }
        }

        public bool EnableNotification
        {
            get { return m_EnableNotification; }
            set { m_EnableNotification = value; }
        }
        protected float m_MaxTV = 0;

        public float MaxTV
        {
            get { return m_MaxTV; }
            set { m_MaxTV = value; }
        }
        protected int m_LockCount = 0;

        public int LockCount
        {
            get { return m_LockCount; }
            set { m_LockCount = value; }
        }
        protected ulong m_ItemCount = 0;
        public ulong ItemCount
        {
            get
            {
                return m_ItemCount;
            }
            set
            {
                m_ItemCount = value;
            }
        }
        protected bool[] m_Locks;

        public bool[] Locks
        {
            get { return m_Locks; }
            set
            {
                m_Locks = value;
                m_LockCount = 0;
                m_ItemCount = 1;
                for (int i = 0; i < m_Locks.Length; i++)
                {
                    if (m_Locks[i])
                    {
                        m_LockCount++;
                    }
                    else
                    {
                        m_ItemCount *= (ulong) m_Items[i].Count;
                    }
                }

            }
        }

        public NotificationDelegate Notify
        {
            get { return m_Notify; }
            set { m_Notify = value; }
        }
        public Character Target
        {
            get { return m_Target; }
            set { m_Target = value; }
        }
        protected List<Item>[] m_Items;


        public List<Item>[] Items
        {
            get { return m_Items; }
            set { m_Items = value; }
        }
        public virtual void Optimize()
        {
            OptimizeAdditional oa = new OptimizeAdditional();
            oa.Target = m_Target;
            oa.Items = m_Items;
            oa.Locks = m_Locks;
            oa.UpdateGraphics = this.UpdateGraphics;
            oa.Optimize();
            if (EnableNotification) Notify();
        }
        public virtual void Abort()
        {
            m_Abort = true;
        }

    }
}
